package shujujiegou;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;


public class SocketService {
	public static void main(String[] args) {
		ServerSocket serverSocket = null;
		Socket socket = null;
		InputStream is = null;
		OutputStream os = null;
		try {
			serverSocket = new ServerSocket(8888);
			while(true){
				socket = serverSocket.accept();
				is = socket.getInputStream();
				byte[] bs = SocketClient.readStream(is);
				System.out.print(new String(bs, "utf-8"));
				System.out.println();
				//����welcome
				os = socket.getOutputStream();
				os.write("welcome".getBytes());
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				os.close();
				is.close();
				socket.close();
				serverSocket.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			
		}
		
		
		
	}
	
	
}
